package mapViewer.screens;

import context.*;

import mapViewer.MapViewer;

import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Ticker;

// ******************************************************************
// *** CLASS: SplashScreen
// ******************************************************************
public class SplashScreen extends Canvas implements Debug.Constants
{ //private static final boolean DEBUG=true; // Overriding Debug.Constants.DEBUG
  private static final Command connectCommand=new Command("Connect",Command.OK,0);
  private static final Command accountCommand=new Command("Account",Command.EXIT,1);
  
  private Image logo;
  private MapViewer midlet;
  
  public SplashScreen(MapViewer midlet)
  { this.midlet=midlet;
    try { logo=Image.createImage("/SunMap.png"); } catch (IOException e) { }

    if(DEBUG) Debug.println("New SplashScreen");
    this.addCommand(connectCommand);
    this.addCommand(accountCommand);
    this.setCommandListener(new CommandListener()
    { public void commandAction(Command c,Displayable s)
      { if(c==connectCommand)
    	{ setTicker(new Ticker("... connecting ..."));	
    	  SplashScreen.this.midlet.connect();
    	}
    	else if(c==accountCommand) SplashScreen.this.midlet.showAccountScreen();
      }
    });
  }
  
  
  public void show() { Context.setCurrent(this); }
  
  public void paint(Graphics g)
  { if(logo!=null)
    { int w=getWidth();
      int h=getHeight();
      g.drawImage(logo,w/2,h/2,Graphics.HCENTER|Graphics.VCENTER);
    }  
  }

}